<template>
  <div>
    <div style="padding-top: 120px">
      <div class="login-box">
        <div class="logo">
          <img src="../assets/imgs/logo.png" alt="易学啦" />
        </div>
        <form class="el-form">
          <!-- 请输入Email -->
          <div class="el-form-item el-form-item--feedback">
            <div class="el-form-item__content">
              <div class="login-input el-input el-input--prefix">
                <input
                  type="text"
                  placeholder="请输入Email"
                  class="el-input__inner"
                  v-model="Email"
                />
                <span class="el-input__prefix">
                  <i class="el-input__icon el-icon-user-solid"></i>
                </span>
              </div>
            </div>
          </div>

          <!-- 请输入密码 -->
          <div class="el-form-item el-form-item--feedback is-required">
            <div class="el-form-item__content">
              <div class="login-input el-input el-input--prefix">
                <input
                  type="password"
                  placeholder="请输入密码"
                  class="el-input__inner"
                  v-popover:popover
                  v-model="PassWord"
                />
                <el-popover
                  ref="popover"
                  placement="right"
                  title="密码要求"
                  width="250"
                  trigger="focus"
                  content="以字母开头，长度在6~18之间，只能包含字母、数字和下划线"
                >
                </el-popover>
                <span class="el-input__prefix">
                  <i class="el-input__icon el-icon-lock"></i>
                </span>
              </div>
            </div>
          </div>
        </form>
        <div class="box-sign">
          <router-link to="/sngin">
            <span class="green cursor">立即注册</span>
          </router-link>
          <span class="cursor"> 忘记密码？</span>
        </div>
        <button type="button" class="el-button sign-btn" @click="submit">
          <span>登陆</span>
        </button>

        <!-- 其他登录方式 -->
        <div class="login-other">
          <div class="other-title">
            <span></span>
            <p>其他登录方式</p>
            <span></span>
          </div>
          <div class="other-icon">
            <div class="login-icon-item">
              <i class="iconfont icon-weixin-copy"></i>
              <span>微信登录</span>
            </div>
            <div class="login-icon-item">
              <i class="iconfont icon-qq"></i>
              <span>QQ登录</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginlists: null,
      Email: "",
      PassWord: "",
      userlists: null,
    };
  },
  methods: {
    submit() {
      this.loginlists = JSON.parse(localStorage.getItem("loginlist")).userlists; //获取数据列表
      console.log("login", this.loginlists);
      let goflag = this.loginlists.some((item) => {
        if (
          item.userPassword == this.PassWord &&
          item.userEmail == this.Email
        ) {
          this.userlists = item;
          return true;
        }
      }); //查找密码与邮箱是否对应
      console.log(goflag);
      console.log(this.userlists);

      if (!goflag) {
        this.$message.error("输入正确的账号密码");
        return;
      }

      // 将用户通行证存储在本地
      let PassID = new Date().getTime();
      console.log(PassID);
      localStorage.setItem("PassID", PassID);
      localStorage.setItem("userList", JSON.stringify(this.userlists));

      // 成功登录
      this.$message({
        showClose: true,
        message: "登录成功，正在跳转主页面",
        type: "success",
      });

      setTimeout(() => {
        this.$emit("showtopFun", true); //显示顶部底部和侧边
        this.$router.push("home");
      }, 2000);
    },
    getUserListFun() {
      localStorage.getItem("userList");
      if (localStorage.getItem("userList")) {
        let emails = JSON.parse(localStorage.getItem("userList")).userEmail;
        this.Email=emails;
      }
    },
  },
  created() {
    this.getUserListFun();
  },
};
</script>

<style lang="scss" scoped>
.cursor {
  cursor: pointer;
}
a {
  text-decoration: none;
  color: #333;
}
.login-box {
  width: 340px;
  background: #fff;
  box-shadow: 0 2px 40px 0 rgb(0 0 0 / 7%);
  border-radius: 10px;
  padding: 40px 60px;
  margin: 0 auto;
  .login-input {
    margin-bottom: 15px;
    margin-bottom: 15px;
  }
  .box-sign {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 400;
    color: #333;
    line-height: 20px;
  }
  .green {
    color: #48c5a3;
  }
  .sign-btn {
    width: 100%;
    margin-top: 25px;
    color: #fff;
    background: #48c5a3;
    border: none;
  }
  .other-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 40px;
    span {
      width: 124px;
      border-bottom: 1px solid #ddd;
      width: 124px;
      border-bottom: 1px solid #ddd;
    }
    p {
      font-size: 12px;
      font-weight: 400;
      color: #999;
      line-height: 17px;
    }
  }
  .other-icon {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-top: 12px;
    .login-icon-item {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      cursor: pointer;
      i {
        width: 50px;
        height: 50px;
        font-size: 50px;
        color: #e8e8e8;
        &:hover {
          color: #48c5a3;
        }
      }
      span {
        margin-top: 10px;
        color: #999;
      }
    }
  }
}
.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  img {
    width: 90px;
    height: 28px;
  }
}
.active-link {
  color: #48c5a3;
}
form {
  display: block;
  margin-top: 0em;
}
.el-form-item {
  margin-bottom: 22px;
}
.el-form-item__content {
  line-height: 40px;
  position: relative;
  font-size: 14px;
}
.el-input {
  position: relative;
  font-size: 14px;
  display: inline-block;
  width: 100%;
  position: relative;
  font-size: 14px;
  display: inline-block;
  width: 100%;
}
.el-input--prefix {
  .el-input__inner {
    padding-left: 30px;
  }
}
.el-input__inner {
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  font-size: inherit;
  height: 40px;
  line-height: 40px;
  outline: 0;
  padding: 0 15px;
  width: 100%;
}
.el-input__prefix {
  left: 5px;
  transition: all 0.3s;
}
.el-input__prefix,
.el-input__suffix {
  position: absolute;
  top: 0;
  height: 100%;
  color: #c0c4cc;
  text-align: center;
}
.el-input__icon {
  height: 100%;
  width: 25px;
  text-align: center;
  transition: all 0.3s;
  line-height: 40px;
}
[class*=" el-icon-"],
[class^="el-icon-"] {
  font-family: element-icons !important;
  font-style: normal;
  font-weight: 400;
  font-feature-settings: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1;
  vertical-align: baseline;
  display: inline-block;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.el-button {
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  background: #fff;
  border: 1px solid #dcdfe6;
  color: #606266;
  text-align: center;
  box-sizing: border-box;
  outline: 0;
  margin: 0;
  transition: 0.1s;
  font-weight: 500;
  padding: 12px 20px;
  font-size: 14px;
  border-radius: 4px;
}
</style>